package com.cleaningcloud.cld.service.impl;

import com.cleaningcloud.cld.domain.dto.CldAssetsRecordDto;
import com.cleaningcloud.cld.domain.vo.CldAssetsRepairDetailsVo;
import com.cleaningcloud.cld.domain.vo.CldAssetsRepairVo;
import com.cleaningcloud.cld.mapper.CldAssetsRepairMapper;
import com.cleaningcloud.cld.service.ICldAssetsRecordService;
import com.cleaningcloud.cld.service.ICldAssetsRepairService;
import com.cleaningcloud.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 资产维修记录Service业务层处理
 * 
 * @author cleaningcloud
 * @date 2024-10-06
 */
@Service
public class CldAssetsRepairServiceImpl implements ICldAssetsRepairService
{
    @Autowired
    private CldAssetsRepairMapper repairMapper;

    @Autowired
    private ICldAssetsRecordService assetsRecordService;


    @Override
    public List<CldAssetsRepairVo> getRepairList(CldAssetsRecordDto cldAssetsRepairDto) {
        return repairMapper.getRepairList(cldAssetsRepairDto);
    }

    @Override
    public List<CldAssetsRepairVo> getRepairGroupProjectList(CldAssetsRecordDto cldAssetsRepairDto) {
        return repairMapper.getRepairGroupProjectList(cldAssetsRepairDto);
    }

    @Override
    public List<CldAssetsRepairVo> getRepairDetailsList(CldAssetsRecordDto cldAssetsRepairDto) {
        List<CldAssetsRepairVo> list = repairMapper.getRepairDetailsList(cldAssetsRepairDto);
        for (CldAssetsRepairVo cldAssetsRepairVo : list) {
            cldAssetsRepairVo.setReportUserName(StringUtils.isEmpty(cldAssetsRepairVo.getReportUserName()) ? cldAssetsRepairVo.getReportUserStaffName() : cldAssetsRepairVo.getReportUserName());
        }
        return list;
    }

    /**
     * @Author Shaw
     * @Description 维修明细详情查看
     * @date: 2025-07-18 15:56
     * @param: //TODO
     */ 
    @Override
    public CldAssetsRepairVo getRepairDetailsByRecordId(Long assetsRecordId) {
        CldAssetsRepairVo obj = repairMapper.getRepairDetailsByRecordId(assetsRecordId);
        List<CldAssetsRepairDetailsVo> detailsList = repairMapper.getRepairListByRecordId(assetsRecordId);
        if(!detailsList.isEmpty()){
            obj.setDetailsList(detailsList);
        }
        return obj;
    }

    @Override
    public int addAssetsRepair(CldAssetsRecordDto cldAssetsRepairDto) {
        return assetsRecordService.insertCldAssetsRecord(cldAssetsRepairDto);
    }
}
